package app.xunxun.homeclock.widget

import android.content.Context
import android.text.Editable
import android.text.TextWatcher
import android.util.AttributeSet
import android.view.View
import android.widget.TextView

class EmptyGoneTextView(context: Context?, attrs: AttributeSet?) : TextView(context, attrs) {

    init {
        this.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }

            override fun afterTextChanged(s: Editable?) {

                if (this@EmptyGoneTextView.visibility == View.VISIBLE) {
                    if (text.isEmpty()) this@EmptyGoneTextView.visibility = View.GONE
                    else this@EmptyGoneTextView.visibility = View.VISIBLE
                }
            }
        })
    }
}